package sd.czw.com.mmgapp.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import sd.czw.com.mmgapp.R;
import sd.czw.com.mmgapp.activity.GoodsDeatilActivity;
import sd.czw.com.mmgapp.model.personalbean.ShoucangModel;

/**
 * Created by czw
 * desc 描述：
 * on 2017/7/18.
 */
public class ShoucangAdapter extends SwipeMenuAdapter<ShoucangAdapter.ShoucangViewHolder> {

    private Context context;
    private List<ShoucangModel.ErrmsgBean> datas;
    private OnShoucangClick onShoucangClick;

    public void setOnShoucangClick(OnShoucangClick onShoucangClick) {
        this.onShoucangClick = onShoucangClick;
    }

    public interface OnShoucangClick{
        void onclick(View itemview,int position);
    }

    public ShoucangAdapter(Context context, List<ShoucangModel.ErrmsgBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(context).inflate(R.layout.shoucang_item, parent, false);
    }

    @Override
    public ShoucangViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new ShoucangViewHolder(realContentView);
    }

    @Override
    public void onBindViewHolder(ShoucangViewHolder holder, final int position) {
        Glide.with(context).load(datas.get(position).getImg()).asBitmap().placeholder(new ColorDrawable(Color.parseColor("#f5f5f5"))).into(holder.ivGoods);
        holder.tvTitle.setText(datas.get(position).getGoods_name());
        holder.tvSale.setText(datas.get(position).getT_price());
        holder.tvSale.setTextColor(ContextCompat.getColor(context,R.color.m_titles));
//        holder.tvSale.setTextColor(context.getColor(R.color.m_titles));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, GoodsDeatilActivity.class);
                intent.putExtra("goods_id",datas.get(position).getGoods_id());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class ShoucangViewHolder extends RecyclerView.ViewHolder{
        @Bind(R.id.iv_goods)
        ImageView ivGoods;
        @Bind(R.id.tv_title)
        TextView tvTitle;
        @Bind(R.id.tv_sale)
        TextView tvSale;
        public ShoucangViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
